Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lodash.curry

Package Overview
Dependencies
Maintainers
3
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lodash.curry

The lodash method `_.curry` exported as a module.

  • 4.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
974K
decreased by-14.83%
Maintainers
3
Weekly downloads
 
Created

What is lodash.curry?

The lodash.curry npm package provides a function that makes it easy to partially apply arguments to a function in a way that is both associative and commutative. This means that you can pass arguments to a curried function one at a time or multiple at once, and in any order, until all arguments have been provided and the original function is executed.

What are lodash.curry's main functionalities?

Currying Functions

Currying a function allows you to create new functions by partially applying some arguments. In this example, we curry the 'add' function and create a new function 'add5' that has the first argument fixed to 5.

const _ = require('lodash.curry');
const add = (a, b, c) => a + b + c;
const curriedAdd = _.curry(add);
const add5 = curriedAdd(5);
console.log(add5(10, 15)); // outputs 30

Associative Currying

Curried functions can be called with arguments one at a time (associative property). This means that the grouping of arguments is irrelevant; the result will be the same.

const _ = require('lodash.curry');
const add = (a, b, c) => a + b + c;
const curriedAdd = _.curry(add);
console.log(curriedAdd(5)(10)(15)); // outputs 30
console.log(curriedAdd(5, 10)(15)); // also outputs 30
console.log(curriedAdd(5)(10, 15)); // also outputs 30

Placeholder Arguments

Lodash.curry supports the use of placeholders. This allows you to skip arguments and provide them later. In this example, we create a function that has the first and third arguments fixed, and the second argument can be provided later.

const _ = require('lodash.curry');
const add = (a, b, c) => a + b + c;
const curriedAdd = _.curry(add);
const add5And = curriedAdd(5, _);
console.log(add5And(10, 15)); // outputs 30

Other packages similar to lodash.curry

Keywords

FAQs

Package last updated on 13 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc